<report title="D2D- Childhood Immunization Combined Report" description="Numbers and percentages for active Patients >=30 months and <=42 months who have at least 1 dose of Men-C, MMR, VZ, 3 doses of Pneu-C, 4 doses of DTaP-IPV-Hib, 2 doses of Rot" active="1">
<query>

select 
count(distinct d2.demographic_no) as "All Patients",
count(distinct d.demographic_no) as "Up to date Patients",
(count(distinct d.demographic_no)/count(distinct d2.demographic_no))*100 as "Percentage"

from demographic d, demographic d2
where (concat(d.year_of_birth,'-',d.month_of_birth,'-',d.date_of_birth) >= date_sub(curdate(), interval 42 month))
and (concat(d.year_of_birth,'-',d.month_of_birth,'-',d.date_of_birth) <= date_sub(curdate(), interval 30 month))

and (concat(d2.year_of_birth,'-',d2.month_of_birth,'-',d2.date_of_birth) >= date_sub(curdate(), interval 42 month))
and (concat(d2.year_of_birth,'-',d2.month_of_birth,'-',d2.date_of_birth) <= date_sub(curdate(), interval 30 month))  

and d.patient_status = "AC" 
and d2.patient_status = "AC" 

and d.demographic_no in
(select dt.demographic_no from preventions dt
where  d.demographic_no=dt.demographic_no
and dt.prevention_type = "DTaP-IPV-Hib"
and dt.deleted = "0"
group by dt.demographic_no having COUNT(dt.id) >= "4")

and d.demographic_no in
(select pn.demographic_no from preventions pn
where  d.demographic_no=pn.demographic_no
and pn.prevention_type = "Pneu-C"
and pn.deleted = "0"
group by pn.demographic_no having COUNT(pn.id) >= "3")

and d.demographic_no in
(select m.demographic_no from preventions m
where  d.demographic_no=m.demographic_no
and m.prevention_type = "MMR"
and m.deleted = "0"
group by m.demographic_no having COUNT(m.id) >= "1")

and d.demographic_no in
(select mn.demographic_no from preventions mn
where  d.demographic_no=mn.demographic_no
and mn.prevention_type = "MenC-C"
and mn.deleted = "0"
group by mn.demographic_no having COUNT(mn.id) >= "1")


and d.demographic_no in
(select v.demographic_no from preventions v
where  d.demographic_no=v.demographic_no
and v.prevention_type = "VZ"
and v.deleted = "0"
group by v.demographic_no having COUNT(v.id) >= "1")

and d.demographic_no in
(select v.demographic_no from preventions v
where  d.demographic_no=v.demographic_no
and v.prevention_type = "Rot"
and v.deleted = "0"
group by v.demographic_no having COUNT(v.id) >= "2")


</query>
</report>